using System.Collections.Generic;

namespace FinMkts
{
    //Nullable types are a pain,can we avoid them?
    public class MarketPrice
    {
        public static readonly ICollection<string> EmptyStringCollection = new string[0];

        /// <summary>
        /// The <see cref="MarketDataProvider"/> specific instrument code
        /// </summary>
        public string ListingCode { get; set; }

        /// <summary>
        /// The buy price of the instrument
        /// </summary>
        public double? Bid { get; set; }

        /// <summary>
        /// The sell price of this instrument
        /// </summary>
        public double? Ask { get; set; }

        /// <summary>
        /// The sell price of this instrument
        /// </summary>
        public double? LastTradePrice { get; set; }

        /// <summary>
        /// Are there any errors in the price?
        /// </summary>
        /// <example>Malformed price messages may contain data that cannot be deserialized</example>
        public ICollection<string> Errors { get; set; }

        public MarketPrice()
        {
            // null object pattern, default to an empty array
            Errors = EmptyStringCollection;   
        }

        public override string ToString()
        {
            return string.Format("{2}: Bid: {0}, Ask: {1}, LastTradePrice: {3}, Errors: {4}", Bid, Ask, ListingCode, LastTradePrice, string.Join(",", Errors));
        }
    }
}